<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>角色列表</title>
   <link href="${basePath}/admin/css/base.css" type="text/css" rel="stylesheet">
   <script type="text/javascript" src="${basePath}/admin/js/jquery.js"></script>
   <script type="text/javascript" src="${basePath}/js/pop.min.js"></script>
</head>
<body>
	
<div id="container" style="background:#f2ffe3 url(${basePath}/admin/images/main_00.jpg) left top repeat-x;">
     <h3 style="height:30px;">
     <a class="button_50" href="${basePath}/admin/game/view">添加新纪录</a>
     </h3>
    <form action="${basePath!}/admin/game/index" method="post">
	    <select name="admin_id" class="select_303">
			<#list admins as a>
				<#if a.id == admin_id>
					<option value="${a.id!}" selected="selected">${a.nickname!}</option>
				<#else>
					<option value="${a.id!}">${a.nickname!}</option>
				</#if>
			</#list>    	
	    </select> 
	    <select name="gametype_id" class="select_103">
			<#list gametypes as g>
				<#if g.id == gametype_id>
					<option value="${g.id!}" selected="selected">${g.name!}</option>
				<#else>
					<option value="${g.id!}">${g.name!}</option>
				</#if>
			</#list>
	    </select>
		<input type="submit" class="button_50" value="筛选"/>    
    </form><br/>
      <table class="dataTable">
          <tr>
	          <th>ID</th>
	          <th>名称</th>
	          <th>排序号</th>
	          <th>icon</th>
	          <th>logo</th>
	          <th>android版本</th>
	          <th>ios版本</th>
	          <th>Andorid下载</th>
	          <th>IOS下载</th>
	          <th>是否收费</th>
	          <th>上线时间</th>
	          <th>评分</th>
	          <th>操作</th>
          </tr>
          <#list games.list as g>
	          <tr>
		          <td>${g.id!}</td>
		          <td>${g.name!}</td>
		          <td>${g.sort_id!}</td>
		          <td><#if g.icon_path??><a href="${basePath!}${g.icon_path}" target="_blank">查看</a><#else>无</#if></td>
		          <td><#if g.image_path??><a href="${basePath!}${g.image_path}" target="_blank">查看</a><#else>无</#if></td>
		          <td><#if g.anroid_path??>已上传<#else>无</#if></td>
		          <td><#if g.ios_path??><a href="${basePath!}${g.ios_path!}" target="_blank">查看</a><#else>无</#if></td>
		          <td>${g.apk_downs!}</td>
		          <td>${g.ios_downs!}</td>
		          <td><#if g.price <= 0.00>免费<#else>收费(${g.price!})</#if></td>
		          <td>${g.create_time?string('yyyy-MM-dd HH:mm:ss')}</td>
		          <td>${g.grade!}</td>
		          <td>
		          	<a href="${basePath}/admin/game/view?id=${g.id!}">修改</a>
		          	<a href="${basePath}/admin/game/delete?id=${g.id!}" onclick="return confirm('你确认要删除这条记录?')">删除</a>
		          	<a href="${basePath}/admin/gamecomment/index?game_id=${g.id!}">管理评论</a>
		          	<a href="javascript:setRank(${g.id!});" >加入排行榜</a>
		          </td>
	          </tr>
          </#list>
   	</table>
   	
   	<#include "${basePath}/admin/common/_paginate.html" />
   	<@paginate currentPage = games.pageNumber totalPage = games.totalPage actionUrl = "/admin/game/index" />
  </div>
  <div id="dialog">
  	<div class="tit">加入排行榜<i class="close">关闭</i></div>
  	<div style="padding:5px;font-size:14px;">
	  	<form name="dialogForm">
	  		<input type="hidden" name="game_id" value="" id="game_id"/>
	  		<span>选择排行榜：</span>
	  		<span id="select_dom">
	  		
	  		</span>
	  		<br/><br/>
	  		<span>排序号：</span>
	  		<span>
	  			<input type="text" class="input_100" name="sort_id" value="-1"/>
	  		</span>
	  		<br/><br/>
	  		<input type="button" class="button_50" value="提交" onclick="submitRank();"/>
	  		<div id="msg" style="color:#528311;font-size:12px;"></div>
	  	</form>
  	</div>
  </div>
	<script type="text/javascript">
		function setRank(gameId){
			$("#game_id").attr("value",gameId);
			$("#msg").empty();
			//第一步ajax请求rank 并拼装select，并放入指定的dom中，弹窗显示
			var select = "<select name='rank_id'>";
			$.ajax({
  			url:"${basePath}/admin/ajax/getRanks",	
  			type:"post",
  			datatype:"json",
  			async:false,
  			success:function(data){
  				for(var num in data){
  					select += "<option value='" + data[num].id + "'>";
  					select += data[num].name;
  					select += "</option>";
  				}
  			}});
			select+="</select>";
			$("#select_dom").html(select);
			//document.dialogForm.game_id.value()=gameId;
			popWin('dialog');
		}
		
		//第二步，点击提交调用函数 获取表单值 发送ajax请求 利用回调函数   将信息返回指定dom中
		
		function submitRank(){
			var rankId = document.dialogForm.rank_id.value;
			var gameId = document.dialogForm.game_id.value;
			var sortId = document.dialogForm.sort_id.value;
			var params={"rank_id":rankId,"game_id":gameId,"sort_id":sortId};
			$.ajax({
	  			url:"${basePath}/admin/game/relateRank",	
	  			type:"post",
	  			data:params,
	  			datatype:"json",
	  			async:false,
	  			success:function(data){
	  				if(data.result){
	  					$("#msg").html("操作成功!3秒后自动关闭窗口");
	  					setTimeout(function(){$(".close").trigger('click')},3000);
	  				}else{
	  					$("#msg").html(data.error);
	  				}
	  			}}
			);
		}
	</script>
</body>
</html>